package com.senjoeson.publicsource.kotlin

import android.graphics.Color
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import com.senjoeson.publicsource.R

/**
 * 指示器页面 --->只需要实现其中的方法即可使用
 */
abstract class BaseMainTabActivity : BaseKotlinActivity() {


    var mViewPager: ViewPager? = null
    var tablayout: TabLayout? = null

    /**
     * 初始化两个控件
     */
    override fun initView() {
        mViewPager = findViewById(R.id.viewpager)
        tablayout = findViewById(R.id.tablayout)


        val myAdapter = SimpleFragmentPagerAdapter(supportFragmentManager)
        myAdapter.setTilte(getTabTitles())
        val fragments = arrayListOf<Fragment>()
        myAdapter.setFragments(initFragments(fragments))

        mViewPager?.adapter = myAdapter
        tablayout?.setTabTextColors(Color.GRAY, Color.WHITE)
        tablayout?.setupWithViewPager(mViewPager)

    }

    /**
     *创建多个fragment进行页面填充
     */
    abstract fun initFragments(fragments: ArrayList<Fragment>): MutableList<Fragment>

    /**
     * 多个fragment对应的指示器标题
     */
    abstract fun getTabTitles(): Array<String>

    /**
     * 返回键 --可以重写
     */
    override fun onBackArrowEvent() {
        //set the left arrow event
        onBackPressed()
    }

    /**
     * 设置页面的标题文字
     */
    override fun setMainTitle(): String {
        return "主题"
    }


}
